#include "Camera.h"
#include "matrix.h"
#include "Formulas3d.h"
#include "../Core/MessageProcessor.h"

#include <assert.h>

Camera::Camera()
{
    m_DxPosition.x = 4.5;
    m_DxPosition.y = 15.0;
    m_DxPosition.z = -20;

    m_DxLookat.x = 4.5;
    m_DxLookat.y = 0.0;
    m_DxLookat.z = 0.0;

    m_DxUpvector.x = 0.0;
    m_DxUpvector.y = 1.0;
    m_DxUpvector.z = 0.0;
}

Camera::~Camera()
{
	//dtor
}

void Camera::HandleMessages()
{
    MessageProcessor &messProc = MessageProcessor::GetInstance();
    CameraMessages &camMessages = messProc.GetCameraMessages();
    for (CameraMessages::iterator cm = camMessages.begin(); cm != camMessages.end(); cm++) {
        handleMessage(*cm);
    }
}

void Camera::handleMessage(CameraMessage &camMess)
{
    switch (camMess.GetType())
    {
        case cmROLL_FORWARD:
            m_RollSpeed = -0.5;
            break;
        case cmROLL_BACKWARD:
            m_RollSpeed = 0.5;
            break;
        case cmROLL_STOP:
            m_RollSpeed = 0;
            break;
        case cmSTRAFE_LEFT:
            m_StrafeSpeed = -0.01;
            break;
        case cmSTRAFE_RIGHT:
            m_StrafeSpeed = 0.01;
            break;
        case cmSTRAFE_STOP:
            m_StrafeSpeed = 0;
            break;

        case cmMOVE_FRONT:
            m_MoveSpeed = -0.01;
            break;
        case cmMOVE_BACK:
            m_MoveSpeed = 0.01;
            break;
        case cmMOVE_STOP:
            m_MoveSpeed = 0;
            break;

        default:
            break;
    }
}

void Camera::Update()
{

}

void Camera::MakeViewMatrix()
{
    D3DXMatrixLookAtLH( &m_DxViewMatrix, &m_DxPosition, &m_DxLookat, &m_DxUpvector);
}














